﻿using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.CSharpAnalyzer.Helpers;
using UMLSynthesizer.LangAnalyzer.Expressions;
using UMLSynthesizer.LangAnalyzer.Statements;

namespace UMLSynthesizer.CSharpAnalyzer.Statements
{
    class CSharpWhileStatement : CSharpStatementBase, IWhileStatement
    {
        #region Fields

        CSharpStatementBlockHelper blockHelper;
        CSharpExpressionHelper expressionHelper;

        #endregion

        #region Constructor

        public CSharpWhileStatement(WhileStatementSyntax statementNode, IStatementBase parentStatement)
            : base(statementNode, parentStatement, null, StatementKinds.While)
        {
            blockHelper = new CSharpStatementBlockHelper(this,
                () =>
                {
                    if (statementNode.Statement.CSharpKind() == SyntaxKind.Block)
                        return (statementNode.Statement as BlockSyntax).Statements;
                    else
                        return new StatementSyntax[] { statementNode.Statement };
                });
            expressionHelper = new CSharpExpressionHelper(null, this,
                () => statementNode.Condition);
        }

        #endregion

        #region Properties

        public IExpressionBase ControlExpression { get { return expressionHelper.Expression; } }
        public IEnumerable<IStatementBase> ContainedStatements { get { return blockHelper.ContainedStatements; } }

        #endregion
    }
}
